//
//  LoadingAnimationView.m
//  news
//
//  Created by lanou on 15/12/21.
//  Copyright © 2015年 lanou. All rights reserved.
//

#import "LoadingAnimationView.h"

@implementation LoadingAnimationView

#pragma mark -
#pragma mark ---加载动画---

- (UIImageView *)loadingView
{
    if (!_loadingView) {
        self.loadingView = [[UIImageView alloc] initWithFrame:CGRectMake((kWidth - 50)/2, (kHeight - 50)/2, 50, 50)];
        self.loadingView.image = [UIImage imageNamed:@"iconfont-loading-3"];
        self.loadingView.transform = CGAffineTransformMakeRotation(0);
        self.loadingView.alpha = 0.8;
    }
    return _loadingView;
}

- (void)beginLoadingWithView:(UIView *)view
{
    [view addSubview:self.loadingView];
    
    CABasicAnimation *jiazaiAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    jiazaiAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2];
    jiazaiAnimation.duration = 0.8;
    jiazaiAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionLinear];
    jiazaiAnimation.cumulative = NO;
    jiazaiAnimation.removedOnCompletion = NO; //No Remove
    jiazaiAnimation.repeatCount = 100;
    [self.loadingView.layer addAnimation:jiazaiAnimation forKey:@"AnimatedKey1"];
}

- (void)endLoading
{
    [self.loadingView removeFromSuperview];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
